# -*- coding: utf-8 -*-
from QuModLibs.Client import *
from QuModLibs.Modules.UI.EnhancedUI import QEScreenNode

# 打印当前客户端玩家ID
print("当前客户端玩家ID: {}".format(playerId))


@QEScreenNode.autoRegister("ui0.main")
class MY_UI(QEScreenNode):
    def __init__(self, namespace, name, param):
        QEScreenNode.__init__(self, namespace, name, param)
        self.createUI()

@QEScreenNode.autoRegister("ui1.main")
class UI_1(QEScreenNode):
    def __init__(self, namespace, name, param):
        QEScreenNode.__init__(self, namespace, name, param)
        
    @QEScreenNode.OnClick("/panel/chain_bt")
    def onClick(self):
        # 获取按钮当前的可见状态文本
        visible = self.GetBaseUIControl("/panel/chain_bt/button_label").asLabel().GetText()
        print(visible)
        if visible == "开":
            self.GetBaseUIControl("/panel/chain_bt/button_label").asLabel().SetText("关")
            data = {
                "playerId": playerId,
                "open": False,
            }
            Call("Call_B",data)
        else:
            self.GetBaseUIControl("/panel/chain_bt/button_label").asLabel().SetText("开")
            data = {
                "playerId": playerId,
                "open": True,
            }
            Call("Call_B",data)

    @QEScreenNode.OnClick("/panel/chain_setting")
    def onClose(self):
        UI_2.createUI()

@QEScreenNode.autoRegister("ui2.main")
class UI_2(QEScreenNode):
    def __init__(self, namespace, name, param):
        QEScreenNode.__init__(self, namespace, name, param)
        
    @QEScreenNode.OnClick("/panel/return")
    def onClose(self):
        print("close")
        self.SetRemove()
    @QEScreenNode.OnClick("/panel/button")
    def onClick(self):
        clain_max = self.GetBaseUIControl("/panel/edit_box").asTextEditBox().GetEditText()
        print(clain_max)
        data = {
            "playerId": playerId,
            "clain_max": clain_max,
        }
        # 获取按钮当前的可见状态文本
        Call("Call_A",data)

@Listen("UiInitFinished")
def onUiInitFinished(args):
    UI_1.createUI()
